﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AssessmentTool.Controls;
using ModelLayer;
using AssessmentTool.ServiceBridge;
using AssessmentTool.PresentationLogic.EventArguments;
using AssessmentTool.Services.DTO;
using AssessmentTool.Services;

namespace AssessmentTool.PresentationLogic.Controllers
{
    public class NormalUserViewController:AbstractController<NormalUserView>
    {
        bool firstProfile = false;

        public NormalUserViewController(NormalUserView element)
            : base(element)
        {
            ed.subscrive("VIEWPROFILE", viewProfiles);
            ed.subscrive("VIEWCOMPETENZE", viewCompetenze);
            ed.subscrive("BACKCOMPETENZE", backCompetenze);
            ed.subscrive("LOGOUT", onLogout);
            ed.subscrive("LOGIN", onLogin);
          
        }

        public void viewProfiles(EventArgs e)
        {
            
            MenuBuilder.getInstance().build("STAGE-PROFILI");
            element.competenzeView.Visibility = Visibility.Collapsed;
            element.profiliView.Visibility = Visibility.Visible;
            if (firstProfile)
            {
                ed.dispatch("OPENLEGEND", null);
                firstProfile = false;
            }
            
        }
        public void viewCompetenze(EventArgs e)
        {
            MenuBuilder.getInstance().build("STAGE-COMPETENZE");
            element.competenzeView.Visibility = Visibility.Visible;
            element.profiliView.Visibility = Visibility.Collapsed;
            
        }
        public void backCompetenze(EventArgs e)
        {
            ed.dispatch("STOPBUSY", null);
            viewCompetenze(e);
        }
        public void onLogout(EventArgs e)
        {
            element.Visibility = Visibility.Collapsed;
        }

        public void onLogin(EventArgs e)
        {
            element.Visibility = Visibility.Visible;
            firstProfile = true;
            viewCompetenze(e);
            ed.dispatch("MENUFIRSTBUILDED", null);
            UtenteLogged ul =(UtenteLogged) Session.getInstance().getValue("USERLOGGED");
            if (!ul.grantVisualizzaProfilo)
                ed.dispatch("ENABLEDISABLEBUTTON", new MenuButtonEventArgs() { Name = "Profili", Enable = false });
        }

       

    }
}
